home *** CD-ROM | disk | FTP | other *** search
/ 3D Games (Spidla) / 3dhry1.iso / mAz Lite 1.0 / input.wdl < prev    next >
Encoding:
Text File  |  2003-03-17  |  5.9 KB  |  213 lines

  1. // Template file v5.202 (02/20/02)
  2. ////////////////////////////////////////////////////////////////////////
  3. // File: input.wdl
  4. //        WDL prefabs for user input (mouse, keyboard, joystick, ..)
  5. ////////////////////////////////////////////////////////////////////////
  6. // Use:
  7. //        Include AFTER "movment.wdl"
  8. //
  9.  
  10.  
  11.  
  12. //@ Input Defines
  13. DEFINE _HANDLE,1;        // SCAN via space key
  14. DEFINE _EXPLODE,2;    // SCAN by an explosion
  15. DEFINE _GUNFIRE,3;    // SHOOT fired by a gun
  16. DEFINE _WATCH,4;        // looking for an enemy
  17. DEFINE _DETECTED,5;    // detected by an enemy
  18. DEFINE _SHOOT1,6;        // shoot key pressed (not used yet)
  19.  
  20.  
  21. //@ Input Vars
  22. var indicator = 0;
  23.  
  24.  
  25. var mouseview = 1;          // mouse factor, set 0 to disable mouse
  26.  
  27.  
  28.  
  29. //@ Input Function Protypes
  30.  
  31. function _player_intentions();    // core function handling input from the player
  32.  
  33. function handle();            // Handle action, calls 'scan_handle'
  34. function scan_handle();        // scan a cone using '_HANDLE' indicator
  35. function perform_handle();    // checks for receining a handle signal
  36. function send_handle();        // send a handle signal (player._SIGNAL = _HANDLE;)
  37.  
  38. function mouse_to_level();    // set TARGET to a point in the level under mouse pointer, return distance
  39.  
  40.  
  41. //@ Input Functions
  42.  
  43. /////////////////////////////////////////////////////////////////////////
  44. // Desc: Get key input from the player
  45. //
  46. // Set aforce & force values using player input (keyboard/mouse/joystick)
  47. // Make sure these values are within limit
  48. //
  49. function _player_intentions()
  50. {
  51. // Set the angular forces according to the player intentions
  52.     aforce.PAN = -astrength.PAN*(KEY_FORCE.X+JOY_FORCE.X);
  53.     aforce.TILT = astrength.TILT*(KEY_PGUP-KEY_PGDN);
  54.     if(MOUSE_MODE == 0)
  55.     {    // Mouse switched off?
  56.          aforce.PAN += -astrength.PAN*MOUSE_FORCE.X*mouseview*(1+KEY_SHIFT);
  57.          aforce.TILT += astrength.TILT*MOUSE_FORCE.Y*mouseview*(1+KEY_SHIFT);
  58.     }
  59.     aforce.ROLL = 0;
  60. // Set ROLL force if ALT was pressed
  61.     if(KEY_ALT != 0)
  62.     {
  63.         aforce.ROLL = aforce.PAN;
  64.         aforce.PAN = 0;
  65.     }
  66. // Double the forces in case the player pressed SHIFT
  67. /*--    if(KEY_SHIFT != 0)
  68.     {
  69.         aforce.PAN += aforce.PAN;
  70.         aforce.TILT += aforce.TILT;
  71.         aforce.ROLL += aforce.ROLL;
  72.     }--*/
  73. // Limit the forces in case the player
  74. // pressed buttons, mouse and joystick simultaneously
  75.     limit.PAN = 2*astrength.PAN;
  76.     limit.TILT = 2*astrength.TILT;
  77.     limit.ROLL = 2*astrength.ROLL;
  78.  
  79.     if(aforce.PAN > limit.PAN) {  aforce.PAN = limit.PAN; }
  80.     if(aforce.PAN < -limit.PAN) {  aforce.PAN = -limit.PAN; }
  81.     if(aforce.TILT > limit.TILT) {  aforce.TILT = limit.TILT; }
  82.     if(aforce.TILT < -limit.TILT) {  aforce.TILT = -limit.TILT; }
  83.     if(aforce.ROLL > limit.ROLL) {  aforce.ROLL = limit.ROLL; }
  84.     if(aforce.ROLL < -limit.ROLL) {  aforce.ROLL = -limit.ROLL; }
  85.  
  86. // Set the cartesian forces according to the player intentions
  87.     force.X = strength.X*(KEY_FORCE.Y+JOY_FORCE.Y);  // forward/back
  88.     force.Y = strength.Y*(KEY_COMMA-KEY_PERIOD);     // side to side
  89.     force.Z = strength.Z*(KEY_HOME-KEY_END);         // up and down
  90.     if(MOUSE_MODE == 0)
  91.     {    // Mouse switched off?
  92.         force.X += strength.X*MOUSE_RIGHT*mouseview;
  93.     }
  94.  
  95. // Double the forces in case the player pressed SHIFT
  96. /*--    if(KEY_SHIFT != 0)
  97.     {
  98.         force.X += force.X;
  99.         force.Y += force.Y;
  100.         force.Z += force.Z;
  101.     }--*/
  102.  
  103. // Limit the forces in case the player tried to cheat by
  104. // operating buttons, mouse and joystick simultaneously
  105.     limit.X = 2*strength.X;
  106.     limit.Y = 2*strength.Y;
  107.     limit.Z = 2*strength.Z;
  108.  
  109.     if(force.X > limit.X) {  force.X = limit.X; }
  110.     if(force.X < -limit.X) { force.X = -limit.X; }
  111.     if(force.Y > limit.Y) {  force.Y = limit.Y; }
  112.     if(force.Y < -limit.Y) { force.Y = -limit.Y; }
  113.     if(force.Z > limit.Z) {  force.Z = limit.Z; }
  114.     if(force.Z < -limit.Z) { force.Z = -limit.Z; }
  115. }
  116.  
  117.  
  118.  
  119. ////////////////////////////////////////////////////////////////////////
  120. // Desc: Handle action. Set to SPACE by default.
  121. // Will operate doors or items within 200 quants.
  122. //
  123. function handle()
  124. {
  125.     if(player != NULL)
  126.     {
  127.         MY_POS.X = player.X;
  128.         MY_POS.Y = player.Y;
  129.         MY_POS.Z = player.Z;
  130.         MY_ANGLE.PAN = player.PAN;
  131.     }
  132.     else
  133.     {
  134.         MY_POS.X = CAMERA.X;
  135.         MY_POS.Y = CAMERA.Y;
  136.         MY_POS.Z = CAMERA.Z;
  137.         MY_ANGLE.PAN = CAMERA.PAN;
  138.     }
  139.     MY_ANGLE.TILT = CAMERA.TILT;
  140.     scan_handle();
  141. }
  142.  
  143.  
  144. /////////////////////////////////////////////////////////////////////////
  145. // Desc: scan a wide cone of 200 quants range
  146. function scan_handle()
  147. {
  148.     temp.PAN = 120;
  149.     temp.TILT = 180;
  150.     temp.Z = 200;
  151.     indicator = _HANDLE;
  152.     scan(MY_POS,MY_ANGLE,temp);
  153. }
  154.  
  155.  
  156.  
  157. /////////////////////////////////////////////////////////////////////////
  158. // Desc: This action can be run by a player entity on the server
  159. //         It checks for receiving a handle signal, then performs a scan
  160. function perform_handle()
  161. {
  162.     while(1)
  163.     {
  164.         if(MY._SIGNAL == _HANDLE)
  165.         {    // client has pressed handle key
  166.             my._SIGNAL = 0;                // reset it
  167.             vec_set(my_pos,my.x);
  168.             vec_set(my_angle,my.pan);
  169.             scan_handle();
  170.         }
  171.         wait(1);
  172.     }
  173. }
  174.  
  175. /////////////////////////////////////////////////////////////////////////
  176. // Desc: send a '_HANDLE' signal
  177. function send_handle()
  178. {
  179.     if(player != NULL)
  180.     {
  181.         player._SIGNAL = _HANDLE;    // send command to perform a scan
  182.         send(player._SIGNAL);
  183.     }
  184. }
  185.  
  186.  
  187. /////////////////////////////////////////////////////////////////////
  188. // Desc: set TARGET to a point in the map that appears under the mouse pointer
  189. //            returns the distance to that point
  190. //
  191. // Modifies: vecTo, vecFrom, TARGET, NORMAL, YOU, TEX_NAME, TEX_LIGHT
  192. // Returns: distance to TARGET (or 0 if NULL)
  193. function mouse_to_level()
  194. {
  195.     vecFrom.X = MOUSE_POS.X;
  196.     vecFrom.Y = MOUSE_POS.Y;
  197.     vecFrom.Z = 10;
  198.     vec_set(vecTo,vecFrom);
  199.     vec_for_screen(vecFrom,CAMERA); // near point
  200.  
  201.     vecTo.Z = 5000;
  202.     vec_for_screen(vecTo,CAMERA);   // far point
  203.  
  204.     return(trace(vecFrom,vecTo));  // trace a line between the two points
  205. }
  206.  
  207.  
  208.  
  209.  
  210.  
  211. /////////////////////////////////////////////////////////////////////
  212. //jcl (key assignments always at the end)
  213. ON_SPACE send_handle;